var request = require("request");
var fs = require("fs"); //node自带的框架
var cheerio = require('cheerio'); //服务端的jQuery
//安装各种框架以便于爬取小说

function getHtml(url) {
    request(url, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            // console.log(body);
            // fs.writeFileSync('test.html', body);
            var $ = cheerio.load(body, { decodeEntities: false });
            var content = $("#content").text();
            var next = $("#pager_next").attr("href");
            var dizhi = site + next;
            console.log(dizhi);
            fs.appendFileSync("从仙侠世界归来.text", content);
            getHtml(dizhi);
        }
    })
}
var site = "http://www.qu.la/book/9468/";
var url = "http://www.qu.la/book/9468/4000983.html";
getHtml(url);